<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>01原型和原型链</title>
	</head>
	<body>
		<h3>何为原型链</h3>
		<p>
			在JavaScript中万物都是对象，对象和对象之间也有关系，并不是孤立存在的。对象之间的继承关系，在JavaScript中是通过prototype对象指向父类对象，直到指向Object对象为止，这样就形成了一个原型指向的链条，专业术语称之为原型链。
		</p>

		<script type="text/javascript">
			function Person(name, age, gender) {
				this.name = name
				this.age = age
				this.gender = gender
				this.sayName = function() {
					alert(this.name);
				}
			}
			var per = new Person("孙悟空", 18, "男");
			console.log(per.__proto__);


			var name = "The Window";
			var object = {
				name: "My Object",
				getNameFunc: function() {
					return function() {
						return this.name;
					};
				}
			};
			console.log(object.getNameFunc());
			//alert();

			var name = "The Window";
			var object = {
				name: "My Object",
				
				getNameFunc: function() {
					var that = this;
					return function() {
						return that.name;
					};
				}
			};
			console.log(object.getNameFunc());
			alert(object.getNameFunc()());
			{ 
			  var i = 9;
			} 
			console.log(i);  // 9
			var j=0;
			{
			    console.log(j);
			}
		</script>
	</body>
</html>
